<?php $header=$this->action('ZfcAdmin\Controller\AdminController', 'headerAction');
	  $baseUrl = $header->headerarray['baseUrl'];
?>
<?php if(isset($_SESSION['admin'])){?>
<html>
	<body>		
		<?php if(isset($_GET['location_id']) && $_GET['location_id']!=""){?>
		<h3>Edit Location:</h3>
		<?}else{?>
		<h3>Add Location:</h3>
		<?}?>
		<center>
			<form id="location_form" name="location_form" method="post" action="">
					<div>
						Districts:<select id="districts" name="districts" onChange="return getAdminDistrictAreas('district');">
							<option value="">Select a district</option>
						<? if(count($this->list_districts)>0){ foreach($this->list_districts as $district){ 
						  if($this->get_location->district_id==$district->district_id){?>
							<option value="<? echo $district->district_id;?>" selected="selected"><? echo $district->district_name;?></option>
						  <? } elseif($_GET['dist_id']==$district->district_id){?>
								<option value="<? echo $district->district_id;?>" selected="selected"><? echo $district->district_name;?></option>
						  <?}else {?>
							<option value="<? echo $district->district_id;?>"><? echo $district->district_name;?></option>
						  <?}?>
						<?}}else{?>
							<option value="">No districts</option>
						<?}?>
						</select><br/>	<br/><br/>
						 Area:<select id="areas" name="areas">
							<option value="">Select a area</option>						
						</select><br/>	<br/><br/>							
						Location:
						<? if(isset($this->get_location->location_id) && $this->get_location->location_id!=""){?>
							<input type="text" id="loc_name" name="loc_name" value="<? echo $this->get_location->location_name;?>">
						<?}else{?>
						<div id="subdiv">			
							<div id ="txtdiv0">
								<input type="text" id="loc_name" name="loc_name[]">&nbsp;&nbsp;
								<input type="button" onclick="addTextBox()" id="add0" value="+">
								<input type="button" onclick="removeTextBox()" id="remove0" style="display:none;" value="-"><br/>
							</div>	
						</div>
						<?}?>
					</div>
				<br/><br/>				
					<a href="<? echo $baseUrl.'admin/location-list'?>">Back</a>&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" id="btn_location" name="btn_location" value="Save" onclick="return add_location()">
					<input type="hidden" id="hid_location" name="hid_location" value="<?  if(isset($this->get_location->location_id) && $this->get_location->location_id!=""){ echo $this->get_location->location_id;}else{}?>">
					<input type="hidden" id="addd_url_dist_id" name="addd_url_dist_id" value="<?  if(isset($_GET['dist_id']) && $_GET['dist_id']!=""){ echo $_GET['dist_id'];}else{}?>">
					<input type="hidden" id="add_url_area_id" name="add_url_area_id" value="<?  if(isset($_GET['area_id']) && $_GET['area_id']!=""){ echo $_GET['area_id'];}else{}?>">
			</form>
		</center>
	</body>
</html>
<script>
$( document ).ready(function() {
	<?php if(isset($_GET['dist_id']) && $_GET['dist_id']!=""){?>	
		getAdminDistrictAreas('district');
	<?php } ?>
});
var i=0;
function addTextBox(){
	i++;
	$('#subdiv').append('<div id = "txtdiv'+i+'"><input type="text" id="loc_name'+i+'"  name="loc_name[]">&nbsp;&nbsp;<input type="button" onclick="addTextBox()" id="add'+i+'" value="+"><input type="button" onclick="removeTextBox()" id="remove'+i+'" value="-"></div>');
	var j = i - 1;
	$('#remove'+j).show();
	$('#remove'+i).hide();
	$('#add'+j).hide();
	
}
function removeTextBox(){
	$('#txtdiv'+i).remove();
	i--;
	$('#remove'+i).hide();
	$('#add'+i).show();
}
</script>
<? } else {?>
<script>
	window.location=ADMIN_BASE_URL+'admin';
</script>
<?}?>
